package com.ellecity06.common.ktx

import android.content.Context
import android.content.res.Resources
import com.ellecity06.common.utils.appContext

/**
 * @author ellecity06
 * @time 2023/4/6 11:41
 * @des
 */


fun Context.dp2px(dp: Int): Int {
    val scale = resources.displayMetrics.density
    return (dp * scale + 0.5f).toInt()
}

fun Context.px2dip(pxValue: Float): Int {
    val scale = resources.displayMetrics.density
    return (pxValue / scale + 0.5f).toInt()
}

fun Float.dp2px(): Int {
    val scale = Resources.getSystem().displayMetrics.density
    return (this * scale + 0.5f).toInt()
}
fun Float.dp(): Float {
    val scale = Resources.getSystem().displayMetrics.density
    return (this * scale + 0.5f)
}

fun Float.sp2px(): Int {
    val scale = Resources.getSystem().displayMetrics.density
    return (this * scale + 0.5f).toInt()
}
fun isFoldExpandStatus():Boolean {
    val foldExpandRate = 1.2
    val currentRate: Double = screenHeight.toDouble() / screenWidth
    if (currentRate <= foldExpandRate) {
        return true
    }
    return false
}
/**
 * 屏幕高度
 */
val screenHeight: Int by lazy { appContext.resources?.displayMetrics!!.heightPixels }

/**
 * 屏幕宽度
 */
val screenWidth: Int by lazy { appContext.resources?.displayMetrics!!.widthPixels }
